class Solution {
public:
    int maxDistinctElements(vector<int>& nums, int k) {
        
        sort(nums.begin(),nums.end());
        int nRet=0;
        int cur=INT_MIN;
        for(int i=0;i<nums.size();++i){
            int left=nums[i]-k;
            int right=nums[i]+k;
            if(cur<left){
                cur=left+1;
                ++nRet;
            }
            else if(cur>=left && cur<=right){
                cur=cur+1;
                ++nRet;
                cout<<cur<<endl;
            }
            
        }

        return nRet;
    }
};
